package cn.njupt.unionfind;

public class Quick_Union_Rank_PathCompression extends Quick_Union_Rank{

    public Quick_Union_Rank_PathCompression(int capacity) {
        super(capacity);
    }

    /**
     * 左程云老师的递归
     * @param child
     * @return
     */

    public int find1(int child) {
        int p=parent[child];
        if(child!=p){
            p=find1(parent[child]);
        }
        parent[child]=p;
        return p;
    }

    /**
     * 马明杰老师的更加精简
     * @param child
     * @return
     */
    @Override
    public int find(int child){
        rangCheck(child);
        if(parent[child]!=child){
            parent[child]=find(parent[child]);
        }
        return parent[child];
    }




}
